layui.use('table', function () {
    const table = layui.table;
    //第一个实例
    table.render({
        elem: '#courseClaList'
        , height: 'full'
        , url: '/teacher/course/must/'  //数据接口
        , parseData: function (res) {
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": changeNature(res.data.data) //解析数据列表
            }
        }
        , title: '已选班级信息表'
        , cols: [[
            {field: 'id', title: 'ID', width: 100}
            , {field: 'courseId', title: '课程号', width: 230}
            , {field: 'courseName', title: '课程名', width: 200}
            , {field: 'teacherId', title: '教师编号', width: 180}
            , {field: 'credit', title: '学分', width: 90}
            , {field: 'nature', title: '课程属性', width: 130}
            , {field: 'relationId', title: '班级', width: 100}
            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100, align: 'center'}

        ]]
        , page: false
    });

    function changeNature(courses) {
        for (let course of courses) {
            if (course.nature === 0) {
                course.nature = '必修课';
            }
        }
        return courses;
    }

    table.on('tool(courseClaList)', function (obj) {
        var data = obj.data;
        if (obj.event === 'edit') {
            sessionStorage.setItem('courseId', data.courseId)
            $("#body-content").load('/pages/teacher/setStudentScores');
        }
    });

})